import { followDoctor } from '@/services/consult'
import type { DoctorItem, FollowType } from '@/types/consult'
import { ref } from 'vue'

// 关注/取消关注
export const useFollow = (type: FollowType) => {
  const loading = ref(false)
  const follow = async (item: { id: string; likeFlag: 0 | 1 }) => {
    // 开启loading
    loading.value = true
    try {
      // 发送请求
      await followDoctor(type, item.id)
      // 手动修改关注状态
      item.likeFlag = item.likeFlag === 1 ? 0 : 1
    } finally {
      // 关闭loading
      loading.value = false
    }
  }

  return { loading, follow }
}
